<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Mail;
class ForgetController extends Controller
{
    // forget
    public function forget()
    {
    	return view('admin.forget.inputEmail');

    }

    //sendEmail
    public function sendEmail(Request $request)
    {
    	// dd($request -> all());

    	$data = $request -> except('_token');
   		
   		$res = DB::table('users') -> where('email',$data['email']) -> first();

   		if(!$res)
   		{ 
   			return back() -> with(['info' => '您输入的邮箱不存在']);
   		}

   		// Mail::raw('你好',  function($message){
   		// 	$message -> to('577370487@qq.com');
   		// 	$message -> subject('这是一个本人发的邮件');
   		// });

   		Mail::send('emails.html',['res' => $res],function($m) use ($data){
   			$m -> subject('这是一个本人发的邮件');
   			$m -> to($data['email']);

   			});
    }

    //reset
    public function reset($id,$remember_token)
    {
    	$data = DB::table('users') -> where('id',$id) -> first();

    	if($data -> remember_token != $remember_token)
    	{
    		return redirect('/admin/foreach/info') -> with(['info' => '这不是合法来源']);
    	}else{
    		return view('admin.forget.newpass');
    	}

    }
    //repass
    public function repass(Request $request)
    {	
    		// dd($request -> all());
    	$data = $request -> execpt('_token');	
    	if($data['password'] == $data['repassword '])

    }else{

    	
    }


    public function info()
    {
    	return view('admin.forget.info');
    }

}
